package com.wy.util.HRBU;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by wy on 2018/2/28.
 */
public class GetCourseMain {

    /**多线程执行*/
    public void threadExecute(){
        String selectCount = "SELECT count(*) as count FROM \"JWXT\".\"V_XS_KB_APP\" where ZXJXJHH = '2017-2018-2'";
        Connection conn = GetCourse2.getConn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        int totalThreadNum;
        try {
            ps = conn.prepareStatement(selectCount);
            rs = ps.executeQuery();
            rs.next();
            totalThreadNum = rs.getInt("count") / 50000 + 1; // 每5万条数据开启一个新线程
            //循环创建多线程
            for (int i = 1; i <= totalThreadNum; i++){
                new Thread(new GetCourse2(i * 50000)).start();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                if (rs != null)
                    rs.close();
                if (ps != null)
                    ps.close();
                if (conn != null)
                    conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

    public static void main(String[] args) {
        GetCourseMain get = new GetCourseMain();
        get.threadExecute();
    }
}
